<?php
namespace QnuiRings\Controller;
use Think\Controller;
// 软件名称：微折促销管理信息系统
// 代码日期：v3.0 2017-9-11
// 作者：杨道泉 
// 文件名：ImageController.class.php 
// 功能： 上传和管理图片

class ImageController extends QnuiBaseController {
	public function upload(){
		Vendor('taobaosdk.top.request.PictureUploadRequest');
		$req = new \PictureUploadRequest;
		$req->setPictureCategoryId(0);
		//附件上传的机制参见PHP CURL文档，在文件路径前加@符号即可
		$req->setImg("@".$_FILES['userfile']["tmp_name"]);
		$req->setImageInputTitle("Test.jpg");
		$req->setTitle("微折上传图片");
		$resp = $this->c->execute($req,session("TOP_SESSION"));
		$this->ajaxReturn(pre_resp($resp));
	}
	public function get_images(){
		$picture_category_id = I("picture_category_id");
		$page_size = I("page_size");
		$page_no = I("page_no");
		

		Vendor('taobaosdk.top.request.PictureGetRequest');
		$req = new \PictureGetRequest;
		// $req->setPictureId("1001");
		$req->setPictureCategoryId($picture_category_id);
		// $req->setDeleted("1");
		// $req->setTitle("标题");
		// $req->setOrderBy("time:desc");
		// $req->setStartDate("2000-01-01 00:00:00");
		// $req->setEndDate("2000-01-01 00:00:00");
		$req->setPageNo($page_no);
		$req->setPageSize($page_size);
		// $req->setModifiedTime("2011-01-01 11:11:11");
		// $req->setClientType("client:computer");
		// $req->setUrls("http://img.alicdn.com/i2xxxxxx.jpg,http://img01.taobacdn.com/i2xxxxxx.jpg");
		$req->setIsHttps("true");
		$resp = $this->c->execute($req,session("TOP_SESSION"));
		//$resp->totalResults=1000000;
		if($resp->totalResults<$page_size){
			//服务器端不返回真实的图片数量
			$resp->totalResults = $page_size*$page_no;
		}else{
			//只能以增量方式控制图片页数
			$resp->totalResults = $page_size*($page_no+10);
		}
		$this->ajaxReturn(pre_resp($resp));
	}
	public function get_image_catgory(){
		$parent_id = I("parent_id");
		
		Vendor('taobaosdk.top.request.PictureCategoryGetRequest');
		$req = new \PictureCategoryGetRequest;
		// $req->setPictureCategoryId($parent_id);
		// $req->setPictureCategoryName("分类");
		// $req->setType("类型");
		$req->setParentId($parent_id);
		// $req->setModifiedTime("2011-01-01 11:11:11");
		$resp = $this->c->execute($req,session("TOP_SESSION"));
		$this->ajaxReturn(pre_resp($resp));
	}
	public function get_items_onsale(){
		$fields = I("fields");
		$seller_cids = I("seller_cids");
		$q = I("q");
		$page_size = I("page_size");
		$page_no = I("page_no");
		
		Vendor('taobaosdk.top.request.ItemsOnsaleGetRequest');
		$req = new \ItemsOnsaleGetRequest;
		$req->setFields($fields);
		$req->setQ($q);
		// $req->setCid("1512");
		$req->setSellerCids($seller_cids);
		$req->setPageNo($page_no);
		// $req->setHasDiscount("true");
		// $req->setHasShowcase("true");
		// $req->setOrderBy("list_time:desc");
		// $req->setIsTaobao("true");
		// $req->setIsEx("true");
		$req->setPageSize($page_size);
		// $req->setStartModified("2000-01-01 00:00:00");
		// $req->setEndModified("2000-01-01 00:00:00");
		// $req->setIsCspu("true");
		// $req->setIsCombine("true");
		$resp = $this->c->execute($req,session("TOP_SESSION"));
		$this->ajaxReturn(pre_resp($resp));
	}
	public function get_seller_cats(){
		$nick = I("nick");
		Vendor('taobaosdk.top.request.SellercatsListGetRequest');
		$req = new \SellercatsListGetRequest;
		$req->setNick($nick);
		// $req->setFields("cid,name");
		$resp = $this->c->execute($req,session("TOP_SESSION"));
		$this->ajaxReturn(pre_resp($resp));
	}
}